Skip to content

Conversation

@tompng
Copy link
Member

@tompng tompng commented Dec 26, 2025

The logic of newline handling to make html <span> tag pretty does not need to be restricted to comment token.
Remove comment-specific condition and make it simple.

What this code is doing

Moves trailing "\n" outside of closing </span> tag to make generated HTML pretty.

<pre>
<span># comment1
</span><span># comment2
<span><span>42</span>
</pre>

<pre>
<span># comment1</span>
<span># comment2</span>
<span>42</span>
</pre>

Background

In most case, only :on_comment token (and weird percent literal string token) might end with "\n" because RDoc::Parser::Ruby has token-squashing.
I'm writing a new syntax highlighter for RDoc and want to make this pretty-html generation applied to other tokens too.
Removing token-squashing will generate more tokens that ends with "\n".

The logic of newline handling to make html <span> tag pretty does not need to be restricted to comment token.
Remove comment-specific condition and make it simple.
@tompng tompng temporarily deployed to fork-preview-protection December 26, 2025 15:41 — with GitHub Actions Inactive
@matzbot
Copy link
Collaborator

matzbot commented Dec 26, 2025

🚀 Preview deployment available at: https://64804086.rdoc-6cd.pages.dev (commit: a9c8214)

Copy link
Member

@kou kou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

"<span class=\"#{style}\">#{text}</span>#{"\n" if comment_with_nl}"
if text.end_with?("\n")
newline = "\n"
text = text.byteslice(0...-1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use chomp or delete_suffix here?

Suggested change
text = text.byteslice(0...-1)
text = text.delete_suffix("\n")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants